//
//  BookDetailPresenter.m
//  iOSCodeLearning
//
//  Created by TFAppleWork-Summer on 2018/1/10.
//  Copyright © 2018年 Ace. All rights reserved.
//

#import "BookDetailPresenter.h"

@implementation BookDetailPresenter


/**
 请求页面数据

 @param url 链接
 @param param 参数
 */
-(void)getTimeBookModelWithUrl:(NSString *)url param:(NSDictionary *)param{
    
    [[NetWorkAssistant shareNetWorkAssistant] setRequestHeaderWithDict:@{@"TOKEN" :@"Timeface-iOS",
                                                                         @"USERID" :@"718385313074",
                                                                         @"DEVICEID" :[[[UIDevice currentDevice] identifierForVendor] UUIDString].mutableCopy
                                                                         }];
    
    [[NetWorkAssistant shareNetWorkAssistant] get:url
                                       parameters:param
                                         progress:nil
                                          success:^(id resposeObject) {
                                              NSLog(@"param:%@",param);
                                              NSLog(@"response :%@",resposeObject);
                                              dispatch_async(dispatch_get_main_queue(), ^{
                                                  NSDictionary *bookInfo = resposeObject[@"bookInfo"];
                                                  NSError *modelError;
                                                  TimeBookModel *timeBookModel = [[TimeBookModel alloc]initWithDictionary:bookInfo error:&modelError];
                                                  if ([self.vc respondsToSelector:@selector(updateBookCoverImage:)])
                                                  {
                                                       [self.vc updateBookCoverImage:timeBookModel.coverImage];
                                                  }
                                              });
                                          }
                                          failure:^(NSError * _Nonnull error) {
                                              NSLog(@"%@",error);

                                          }];
}

- (void)applyToStore:(NSString *)url param:(NSDictionary *)param{
        [[NetWorkAssistant shareNetWorkAssistant] post:url
                                        parameters:param
                                          progress:nil
                                           success:^(id resposeObject) {
                                               if ([self.vc respondsToSelector:@selector(applyToStoreResposet:)]) {
                                                   [self.vc applyToStoreResposet:resposeObject];
                                               }

                                           }
                                           failure:^(NSError * _Nonnull error) {
                                               NSLog(@"error %@",error);
                                           }];
    
    
    
}


@end
